﻿Imports System.IO
Imports System.Text
Imports MpqReader
Public Class frmLoad
    Public FileList As New System.Collections.Generic.Dictionary(Of String, FileListEntry)
    Public Structure FileListEntry
        Dim Archive As String
        Dim Path As String
        Dim Size As Integer
    End Structure
    Private Sub frmLoad_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Version.Text = My.Application.Info.Version.ToString
        If My.Application.Info.Title <> "" Then
            ApplicationTitle.Text = My.Application.Info.Title
        Else
            ApplicationTitle.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName)
        End If
        Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
        If My.Settings.FirstRun = True Then
            Dim RegKey As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Blizzard Entertainment\World of Warcraft\")
            Dim DataLoc As String = RegKey.GetValue("InstallPath") + "Data\"
            My.Settings.MPQList(0) = DataLoc + "common.mpq"
            My.Settings.MPQList(1) = DataLoc + "patch.mpq"
            My.Settings.MPQList(2) = DataLoc + "common-2.mpq"
            My.Settings.MPQList(3) = DataLoc + "patch-2.mpq"
            My.Settings.MPQList(4) = DataLoc + "expansion.mpq"
            My.Settings.MPQList(5) = DataLoc + "lichking.mpq"
            My.Settings.FirstRun = False
        End If
        Timer.Start()
    End Sub
    Public Sub MPQ_Loading()
        'Path to the WoW Data directory. Retrieved from registry.
        Dim regKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Blizzard Entertainment\World of Warcraft")
        'The key below is needed on a Vista/XP 64bit installation
        If regKey Is Nothing Then
            regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\Blizzard Entertainment\World of Warcraft")
        End If

        Dim DataPath As String = regKey.GetValue("InstallPath") & "Data\"

        Dim myMPQ As New MPQ
        myMPQ.PopulateFileList(My.Settings.MPQList(0))
        For Each a As MPQ.FileListEntry In myMPQ.FileList.Values
            If a.Path.Contains(".m2") Then
                If a.Path.ToLower.StartsWith("character\") Then
                    frmMain.tvModels.Nodes(0).Nodes.Add(a.Path)
                ElseIf a.Path.ToLower.StartsWith("creature\") Then
                    frmMain.tvModels.Nodes(1).Nodes.Add(a.Path)
                ElseIf a.Path.ToLower.StartsWith("item\") Then
                    frmMain.tvModels.Nodes(2).Nodes.Add(a.Path)
                End If
            End If
        Next
        frmMain.Show()
        Me.Close()
    End Sub

    Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
        MPQ_Loading()
        Timer.Stop()
    End Sub
End Class
